<template>
	<view class="bankCardList">
		<view class="uni-list ">
		<view class="uni-list-cell" v-for="(item,index) in cardList" :key="index" @tap="gowithdraw(item)" @longpress="delBankCard(item)">
			<view class="top">
				<image src="../../static/images/yinhang.png" mode="widthFix"></image>
				<view class="bankBox">
					<view class="bankName">
						{{item.bank}}
					</view>
					<view class="bankType">
						{{item.cardType}}
					</view>
				</view>
			</view>
			<view class="bankNum">
				{{item.bankCard}}
			</view>
		</view>
	</view>
	<view class="addBankCard" @tap="addCard">
		<image src="../../static/images/add.png" mode="widthFix"></image>
		添加银行卡
	</view>
	</view>
	
</template>

<script>
	export default{
		data() {
			return {
				cardList: [],
				isWithdtaw:""
			}
		},
		onLoad(e) {
			if(e.isWithdtaw){
				this.isWithdtaw = e.isWithdtaw
			}
		},
		onShow() {
			this.getDataList()
		},
		methods:{
			getDataList(){
				let data = {
					accountId:uni.getStorageSync('buyerAccountId'),
					pageNum:0,
					pageSize:0
				}
				this.$http.post('/api/v1.0/user/queryAccountExtBankByAccountId',data,res=>{
					this.cardList = res.data.data.list
				})
			},
			addCard(){
				uni.navigateTo({
					url:'addBank'
				})
			},
			gowithdraw(item){
				if(this.isWithdtaw == 1){
					uni.$emit('selectBankCard',item)
					uni.navigateBack()
				}
			},
			delBankCard(item){
				console.log(item)
				var _this = this;
				uni.showModal({
				    content: '确定要把该银行卡删除吗？',
					confirmColor:"#F63810",
				    success: function (res) {
				        if (res.confirm) {
								let data = {
								  "accountId": item.accountId,
								  "bankCard": item.bankCard,
								}
				            
				            _this.$http.post('/api/v1.0/user/removeBank',data,res=>{
				            	if(res.data.status == '000000'){
				            		uni.showToast({
				            			title:"删除成功！",
				            			icon:"none"
				            		})
				            	}else{
				            		uni.showToast({
				            			title:"删除失败，请稍后再试！",
				            			icon:"none"
				            		})
				            	}
				            	
				            	_this.getDataList()
				            })
						 }
				         else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
				
			}
		}
	}
</script>

<style lang="scss">
	.bankCardList{
		width: 100%;
		min-height: 100vh;
		padding-top: 30upx;
		background-color: #f2f2f2;
		.uni-list{
			width: 694upx;
			margin: 0 auto;
			.uni-list-cell{
				background-color: #fff;
				margin-bottom: 20upx;
				border-radius: 20upx;
				padding: 40upx 30upx;
				.top{
					display: flex;
					justify-content: flex-start;
					align-items: center;
					image{
						width: 68upx;
						height: 68upx;
					}
					.bankBox{
						margin-left: 10upx;
						.bankName{
							color: #4d4d4d;
							font-size: 32upx;
						}
						.bankType{
							font-size: 24upx;
							color: #999;
						}
					}
				}
				.bankNum{
					color: #404040;
					font-size: 48upx;
					font-weight: bold;
					padding-left: 78upx;
					box-sizing: border-box;
					margin-top: 42upx;
				}
			}
		}
		.addBankCard{
			display: flex;
			align-items: center;
			width: 694upx;
			margin: 40upx auto;
			line-height: 80upx;
			border-bottom: 1upx solid #d9d9d9;
			image{
				width: 37upx;
				height: 37upx;
				margin-right: 15upx;
			}
			font-size: 28upx;
			color: #bfbfbf;
		}
	}
</style>
